package hu.bme.orarend.client;

import hu.bme.orarend.shared.RoomDTO;

import java.util.List;

import org.gwt.advanced.client.datamodel.EditableGridDataModel;
import org.gwt.advanced.client.ui.widget.GridPanel;
import org.gwt.advanced.client.ui.widget.cell.LabelCell;

public class RoomGridPanel extends GridPanel
{
  private String[][] data = new String[1][1];
  EditableGridDataModel editableGridDataModel = new EditableGridDataModel( data );
  
  public void createRoomGrid( )
  {
    this.createEditableGrid( new String[]{ "Teremnév", "Épület", "Emelet", "Ajtó", "Befogadóképesség", "Típus", "Projektor", "Hangosítás" },
                                    new Class[]{ LabelCell.class, LabelCell.class, LabelCell.class, LabelCell.class, LabelCell.class, LabelCell.class, LabelCell.class, LabelCell.class },
                                    editableGridDataModel );
    this.getGrid().enableVerticalScrolling( true );
    this.getGrid().setBodyHeight( "150px" );
    this.setBottomPagerVisible(false);
    this.setTopPagerVisible(false);
    this.setBottomToolbarVisible(false);
    this.setTopToolbarVisible(false);
    this.setHeight("100px");
    this.display();
  }
  
  public void refreshData( List<RoomDTO> roomList )
  {
    this.unlock();
    data = new String[roomList.size()][8];
    int i = 0;
    for( RoomDTO roomDTO:roomList )
    {
      data[i][0] = roomDTO.getName();
      data[i][1] = roomDTO.getBuilding();
      data[i][2] = roomDTO.getFloor();
      data[i][3] = roomDTO.getDoor();
      data[i][4] = String.valueOf( roomDTO.getCapacity() );
      data[i][5] = ("0".equals( roomDTO.getType()))?(RoomDTO.TYPE_0):(RoomDTO.TYPE_1);
      data[i][6] = ((roomDTO.getProjector() == true)?RoomDTO.YES:RoomDTO.NO);
      data[i][7] = ((roomDTO.getAmplifier() == true)?RoomDTO.YES:RoomDTO.NO);
      i++;
    }
    editableGridDataModel.update( data );
    this.lock();
    this.adjust();
  }
}
